package a51qindian.com.comprehensive.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.jude.rollviewpager.RollPagerView;
import com.li.interfaces.OnItemClickListener;

import java.util.ArrayList;
import java.util.List;

import a51qindian.com.comprehensive.Const;
import a51qindian.com.comprehensive.R;
import a51qindian.com.comprehensive.activity.AddCouponActivity;
import a51qindian.com.comprehensive.activity.AgentListActivity;
import a51qindian.com.comprehensive.activity.CityApplyActivity;
import a51qindian.com.comprehensive.activity.CityDeviceManagerActivity;
import a51qindian.com.comprehensive.activity.CityRepairActivity;
import a51qindian.com.comprehensive.activity.CityShopManagerActivity;
import a51qindian.com.comprehensive.activity.CityStaffManagerActivity;
import a51qindian.com.comprehensive.activity.FirstInstallActivity;
import a51qindian.com.comprehensive.activity.GetCrashActivity;
import a51qindian.com.comprehensive.activity.IncomeExpenseActivity;
import a51qindian.com.comprehensive.activity.QRCodeActivity;
import a51qindian.com.comprehensive.activity.ShopAdvListActivity;
import a51qindian.com.comprehensive.activity.ShopDeviceManagerActivity;
import a51qindian.com.comprehensive.activity.ShopGetCrashApplyActivity;
import a51qindian.com.comprehensive.activity.ShopListActivity;
import a51qindian.com.comprehensive.activity.TaskProcessingActivity;
import a51qindian.com.comprehensive.base.QDBaseFragment;
import a51qindian.com.comprehensive.city.FunctionAdapter;
import a51qindian.com.comprehensive.city.HeaderPagerAdapter;
import a51qindian.com.comprehensive.model.FunctionModel;
import butterknife.BindView;

/**
 * Author: Li
 * Date: 2017/9/12 0012
 * Description: 工作中心
 */

public class WorkCenterFragment extends QDBaseFragment {

    @BindView(R.id.pager_header)
    RollPagerView mPagerHeader;
    @BindView(R.id.recycler_function)
    RecyclerView mRecyclerFunction;

    private HeaderPagerAdapter mHeaderPagerAdapter;
    private List<FunctionModel> mFunctionModelList;
    private FunctionAdapter mFunctionAdapter;
    private static final int SPAN_COUNT = 4;

    public static WorkCenterFragment newInstance(String type) {

        Bundle bundle = new Bundle();
        bundle.putString(Const.USER_TYPE, type);
        WorkCenterFragment fragment = new WorkCenterFragment();
        fragment.setArguments(bundle);
        return fragment;
    }

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_work_center;
    }

    @Override
    protected void initSth() {
        super.initSth();

        mFunctionModelList = new ArrayList<>();
        mFunctionAdapter = new FunctionAdapter(mContext);
        if (getArguments() != null) {
            mFunctionModelList.clear();
            String type = getArguments().getString(Const.USER_TYPE, Const.TYPE_REPAIRMAN);
            switch (type) {
                case Const.TYPE_CITY:
                    mFunctionModelList.add(new FunctionModel(R.drawable.ic_shop_manage, "店铺管理", CityShopManagerActivity.class, 101));
                    mFunctionModelList.add(new FunctionModel(R.drawable.ic_staff_manage, "员工管理", CityStaffManagerActivity.class, 102));
                    mFunctionModelList.add(new FunctionModel(R.drawable.ic_device_manage, "设备管理", CityDeviceManagerActivity.class, 103));
                    mFunctionModelList.add(new FunctionModel(R.drawable.ic_apply, "申请单", CityApplyActivity.class, 104));

                    mFunctionModelList.add(new FunctionModel(R.drawable.ic_repair, "维修单", CityRepairActivity.class, 105));
                    mFunctionModelList.add(new FunctionModel(R.drawable.ic_income_expense, "收支记录", IncomeExpenseActivity.class, 106));
//                    mFunctionModelList.add(new FunctionModel(R.drawable.ic_shop_verify, "店铺审核", CityShopVerifyActivity.class, 107));
                    mFunctionModelList.add(new FunctionModel(R.drawable.ic_get_crash, "提现申请", GetCrashActivity.class, 107));
                    mFunctionModelList.add(new FunctionModel(R.drawable.ic_first_install, "首装分配", FirstInstallActivity.class, 108));

                    mFunctionModelList.add(new FunctionModel(R.drawable.ic_get_crash, "店铺提现", ShopGetCrashApplyActivity.class, 109));
//                    mFunctionModelList.add(new FunctionModel(R.drawable.ic_adv, "广告审核", CityAdvActivity.class, 110));

                    break;
                case Const.TYPE_SHOP:
                    mFunctionModelList.add(new FunctionModel(R.drawable.ic_shop_manage, "设备管理", ShopDeviceManagerActivity.class, 201));
                    mFunctionModelList.add(new FunctionModel(R.drawable.ic_get_crash, "提现申请", GetCrashActivity.class, 202));
                    mFunctionModelList.add(new FunctionModel(R.drawable.ic_income_expense, "收支记录", IncomeExpenseActivity.class, 203));
                    mFunctionModelList.add(new FunctionModel(R.drawable.ic_adv, "置顶广告", ShopAdvListActivity.class, 204));
                    mFunctionModelList.add(new FunctionModel(R.drawable.ic_add_coupon, "新增优惠券", AddCouponActivity.class, 205));
                    mFunctionModelList.add(new FunctionModel(R.drawable.ic_qr_code, "验证优惠券", QRCodeActivity.class, 206));
                    break;
                case Const.TYPE_REPAIRMAN:
                    mFunctionModelList.add(new FunctionModel(R.drawable.ic_task_first_install, "首装任务", TaskProcessingActivity.class, 301));
                    mFunctionModelList.add(new FunctionModel(R.drawable.ic_task_add, "加装任务", TaskProcessingActivity.class, 302));
                    mFunctionModelList.add(new FunctionModel(R.drawable.ic_task_repair, "维修任务", TaskProcessingActivity.class, 303));
                    break;
                case Const.TYPE_MAX_LEVEL:
                    mFunctionModelList.add(new FunctionModel(R.drawable.ic_agent,"区代管理",AgentListActivity.class,401));
                    mFunctionModelList.add(new FunctionModel(R.drawable.ic_income_expense,"我的钱包",IncomeExpenseActivity.class,402));
                    mFunctionModelList.add(new FunctionModel(R.drawable.ic_shop_look,"店铺查看",ShopListActivity.class,403));
                    mFunctionModelList.add(new FunctionModel(R.drawable.ic_get_crash,"提现申请",GetCrashActivity.class,404));
                    mFunctionModelList.add(new FunctionModel(R.drawable.ic_get_crash, "提现审核", ShopGetCrashApplyActivity.class, 405));
                    break;
            }
        }

    }

    @Override
    protected void onFirstVisible() {
        super.onFirstVisible();
        mHeaderPagerAdapter = new HeaderPagerAdapter(mPagerHeader);
        mPagerHeader.setAdapter(mHeaderPagerAdapter);
        mRecyclerFunction.setLayoutManager(new GridLayoutManager(mContext, SPAN_COUNT));
        mRecyclerFunction.setAdapter(mFunctionAdapter);
        mFunctionAdapter.setFunctionModelList(mFunctionModelList);
        mFunctionAdapter.setItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(View view, int pos) {
                Class c = mFunctionModelList.get(pos).getJumpClass();
                int tag = mFunctionModelList.get(pos).getTag();
                switch (tag) {
                    case 206:
                        Intent verifyIntent=new Intent(mContext,c);
                        verifyIntent.putExtra("source","verify");
                        startActivity(verifyIntent);
                        break;
                    case 301:
                        Intent intentFirstInstall = new Intent(mContext, c);
                        intentFirstInstall.putExtra("type", TaskProcessingActivity.TYPE_FIRST_INSTALL);
                        startActivity(intentFirstInstall);
                        break;
                    case 302:
                        Intent intent = new Intent(mContext, c);
                        intent.putExtra("type", TaskProcessingActivity.TYPE_ADD_INSTALL);
                        startActivity(intent);
                        break;
                    case 303:
                        Intent repairIntent=new Intent(mContext,c);
                        repairIntent.putExtra("type",TaskProcessingActivity.TYPE_REPAIR);
                        startActivity(repairIntent);
                        break;
                    default:
                        startActivity(new Intent(mContext, c));
                        break;
                }
            }
        });
    }
}
